package game;
import java.awt.*;
import java.util.*;

public class Target extends Unit
{
	private Snake snake;
	private Random r = new Random();
	private Color mousePink = new Color(255, 174, 201);
	private Color mouseGrey = new Color(200, 200, 200);
	private Color mouseBrown = new Color(185, 122, 87);

	public Target(Snake s)
	{
		snake = s;
		resetTarget();
	}
	public Target(Snake s, int targetID) 
	{
		snake = s;
		setTargetLocation(targetID);
	}
	private void setTargetLocation(int targetID) 
	{
		ArrayList<Point> points = Map.getTargets();
		x = points.get(targetID).x*10;
		y = points.get(targetID).y*10;
	}
	private void resetTarget()
	{
		x = (r.nextInt(Map.getWidth())) * 10;
		y = (r.nextInt(Map.getHeight())) * 10;
		if(snake.outOfBounds(x, y) || Map.isSolid(x, y))
		{
			resetTarget();
		}
	}

	public void paint(Graphics g)
	{
		g.setColor(mouseGrey);
		g.fillRect(x + 1, y + 4, 8, 4);
		g.fillRect(x + 2, y + 3, 6, 6);
		g.fillRect(x + 3, y + 2, 4, 8);
		g.setColor(mouseBrown);
		g.fillRect(x + 4, y + 9, 2, 1);
		g.setColor(Color.white);
		g.fillRect(x + 4, y + 10, 2, 1);
		g.setColor(mousePink);
		g.fillRect(x + 1, y + 3, 2, 2);
		g.fillRect(x + 7, y + 3, 2, 2);
		g.fillRect(x + 5, y, 2, 1);
		g.fillRect(x + 4, y + 1, 3, 1);
		g.fillRect(x + 7, y - 1, 1, 2);
		g.setColor(Color.black);
		g.fillRect(x + 3, y + 6, 1, 2);
		g.fillRect(x + 6, y + 6, 1, 2);
	}
}
